package com.cskaoyan.controller;


import com.cskaoyan.bean.baseresultVO.BaseData;
import com.cskaoyan.bean.baseresultVO.BaseParam;
import com.cskaoyan.bean.baseresultVO.BaseRespVo;
import com.cskaoyan.bean.domain.AfterSale;
import com.cskaoyan.service.AfterSaleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 售后表 前端控制器
 * </p>
 *
 * @author looper
 * @since 2021-11-29
 */
@Controller
@RequestMapping("admin/aftersale")
public class AfterSaleController {

    @Resource
    AfterSaleService service;

    @ResponseBody
    @GetMapping("list")
    public BaseRespVo getList(BaseParam param, String status, String aftersaleSn, String orderId) {
        Short statusValue = null;
        try {
            statusValue = Short.valueOf(status.trim());
        } catch (Exception e) {
            e.printStackTrace();
        }

        Integer orderIdValue = null;
        try {
            orderIdValue = Integer.valueOf(orderId.trim());
        } catch (Exception e) {
            e.printStackTrace();
        }

        BaseData baseData = service.getList(param, statusValue, aftersaleSn, orderIdValue);
        return BaseRespVo.ok(baseData);
    }

    @ResponseBody
    @PostMapping("batch-recept")
    public BaseRespVo batchRecept(@RequestBody Map map ) {
        List<Integer> ids = (List<Integer>) map.get("ids");


        service.batchRecept(ids);
        return BaseRespVo.ok(null);
    }

    @ResponseBody
    @PostMapping("batch-reject")
    public BaseRespVo batchReject(@RequestBody List<Integer> ids) {
        service.batchReject(ids);
        return BaseRespVo.ok(null);
    }

    @ResponseBody
    @PostMapping("recept")
    public BaseRespVo recept(@RequestBody AfterSale afterSale) {
        service.recept(afterSale);
        return BaseRespVo.ok(null);
    }



    @ResponseBody
    @PostMapping("refund")
    public BaseRespVo refund(@RequestBody AfterSale afterSale) {
        //TODO 未知状况
        service.refund(afterSale);
        return BaseRespVo.ok(null);
    }

    @ResponseBody
    @PostMapping("reject")
    public BaseRespVo reject(@RequestBody AfterSale afterSale) {
        service.reject(afterSale);
        return BaseRespVo.ok(null);
    }

}

